package com.hxzy.mapper.system;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hxzy.entity.system.SysRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

@Mapper
public interface SysRoleMapper extends BaseMapper<SysRole> {

    /**
     * 根据用户ID查询角色值
     * @param userId
     * @return
     */
    @Select(value = "SELECT sys_role.role_key  FROM  sys_user_role INNER JOIN sys_role ON sys_user_role.role_id = sys_role.id where  sys_user_role.user_id=#{userId}  and sys_role.`status`='0'")
    Set<String> getOwnRoleKey(Long userId);

    /**
     * 根据用户ID查询角色应的菜单权限
     * @param userId
     * @return
     */
    Set<String> getOwnRoleMenuPerms(Long userId);

    /**
     * mybatis批量插入值
     * @param id
     * @param owernMenus
     * @return
     */
    int addBatch(@Param(value = "id") Long id, @Param(value = "owernMenus") Long[] owernMenus);

    /**
     * 根据id删除 sys_role_menu
     * @param id 角色id
     * @return
     */
    int deleteByRoleId(Long id);
}